{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n"
     ]
    }
   ],
   "source": [
    "# -*- coding: utf-8 -*-\n",
    "import random\n",
    "import numpy as np\n",
    "import logging\n",
    "\n",
    "import tensorflow as tf\n",
    "from keras import losses\n",
    "\n",
    "import gameMetaSquares as game\n",
    "import agent\n",
    "import MCTS\n",
    "from collections import deque\n",
    "\n",
    "import itertools\n",
    "import copy\n",
    "\n",
    "from keras.models import clone_model\n",
    "\n",
    "\n",
    "%matplotlib inline\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "import sys\n",
    "\n",
    "from utils import setup_logger\n",
    "\n",
    "import constants\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<module 'MCTS' from 'MCTS.pyc'>"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "reload(game)\n",
    "reload(agent)\n",
    "reload(MCTS)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "BEST PLAYER VERSION 0\n",
      "('MEMORY LENGTH: ', 1200)\n",
      "BEST PLAYER VERSION 0\n",
      "('MEMORY LENGTH: ', 2400)\n",
      "BEST PLAYER VERSION 0\n",
      "('MEMORY LENGTH: ', 3600)\n",
      "BEST PLAYER VERSION 0\n",
      "('MEMORY LENGTH: ', 4800)\n",
      "BEST PLAYER VERSION 0\n",
      "('MEMORY LENGTH: ', 6000)\n",
      "BEST PLAYER VERSION 0\n",
      "('MEMORY LENGTH: ', 7200)\n",
      "BEST PLAYER VERSION 0\n",
      "('MEMORY LENGTH: ', 8400)\n",
      "BEST PLAYER VERSION 0\n",
      "{'loss': [2.9809173984527586, 2.8091223640441894, 2.7184040203094484, 2.677525520324707, 2.6451940555572508]}\n",
      "('BEST LOSSES ', 0.28495399158613455, ' ', 2.7919728237453136)\n",
      "('CURRENT LOSSES ', 0.19867963770037528, ' ', 2.476446520226248)\n",
      "{'player2': 3, 'drawn': 15, 'player1': 2}\n",
      "()\n",
      "BEST PLAYER VERSION 1\n",
      "{'loss': [2.6621747150421142, 2.6129477195739748, 2.5742757263183593, 2.5610248165130614, 2.5381846084594728]}\n",
      "('BEST LOSSES ', 0.18706670786463314, ' ', 2.4931423949326383)\n",
      "('CURRENT LOSSES ', 0.19215258251850845, ' ', 2.4140823414191379)\n",
      "{'player2': 3, 'drawn': 8, 'player1': 9}\n",
      "()\n",
      "BEST PLAYER VERSION 1\n",
      "{'loss': [2.6323319644927978, 2.5431718311309814, 2.5371702671051026, 2.4886368007659914, 2.4786871318817139]}\n",
      "('BEST LOSSES ', 0.20025221978171368, ' ', 2.5144008292413225)\n",
      "('CURRENT LOSSES ', 0.19962092543558405, ' ', 2.2955301161452191)\n",
      "{'player2': 1, 'drawn': 17, 'player1': 2}\n",
      "()\n",
      "BEST PLAYER VERSION 1\n",
      "{'loss': [2.584030527114868, 2.5447716274261474, 2.5079274806976319, 2.5089964084625245, 2.5126730709075926]}\n",
      "('BEST LOSSES ', 0.23947505711890191, ' ', 2.5319093964407631)\n",
      "('CURRENT LOSSES ', 0.25661414098513702, ' ', 2.3108386712269438)\n",
      "{'player2': 8, 'drawn': 12, 'player1': 0}\n",
      "()\n",
      "BEST PLAYER VERSION 2\n",
      "{'loss': [2.5883236865997317, 2.524288921356201, 2.4946692466735838, 2.5026643428802489, 2.4872221965789794]}\n",
      "('BEST LOSSES ', 0.27894629656659153, ' ', 2.3175409369930002)\n",
      "('CURRENT LOSSES ', 0.25852868438892584, ' ', 2.2443412120469306)\n",
      "{'player2': 3, 'drawn': 11, 'player1': 6}\n",
      "()\n",
      "BEST PLAYER VERSION 2\n",
      "{'loss': [2.5500512886047364, 2.528352586746216, 2.4966310329437258, 2.5076614055633546, 2.5503578834533691]}\n",
      "('BEST LOSSES ', 0.31383214784071467, ' ', 2.3280533475118137)\n",
      "('CURRENT LOSSES ', 0.31265328926343255, ' ', 2.228438294159496)\n",
      "{'player2': 2, 'drawn': 15, 'player1': 3}\n",
      "()\n",
      "BEST PLAYER VERSION 2\n",
      "{'loss': [2.5732047233581543, 2.5768802185058592, 2.5273358974456785, 2.5188268814086916, 2.5075530796051027]}\n",
      "('BEST LOSSES ', 0.32618514451007086, ' ', 2.3374884569932002)\n",
      "('CURRENT LOSSES ', 0.32485131548501583, ' ', 2.1791779074240853)\n",
      "{'player2': 5, 'drawn': 9, 'player1': 6}\n",
      "()\n",
      "BEST PLAYER VERSION 2\n",
      "{'loss': [2.5994212150573732, 2.609335069656372, 2.6145225944519042, 2.6093554477691652, 2.6132788429260252]}\n",
      "('BEST LOSSES ', 0.36134390791499726, ' ', 2.3471648222722705)\n",
      "('CURRENT LOSSES ', 0.36157040175607802, ' ', 2.2756295137754021)\n",
      "{'player2': 2, 'drawn': 11, 'player1': 7}\n",
      "()\n",
      "BEST PLAYER VERSION 2\n",
      "{'loss': [2.6894630260467531, 2.6597728500366209, 2.672073236465454, 2.6864543819427489, 2.6906977081298828]}\n",
      "('BEST LOSSES ', 0.40717762156172549, ' ', 2.3572545685493713)\n",
      "('CURRENT LOSSES ', 0.39049298843170133, ' ', 2.2842661943881786)\n",
      "{'player2': 4, 'drawn': 10, 'player1': 6}\n",
      "()\n",
      "BEST PLAYER VERSION 2\n",
      "{'loss': [2.6778065681457521, 2.670836769104004, 2.6523827419281005, 2.6406003513336183, 2.6360117130279539]}\n",
      "('BEST LOSSES ', 0.39425107975533569, ' ', 2.3623578298077592)\n",
      "('CURRENT LOSSES ', 0.35502161044535269, ' ', 2.2535186679693453)\n",
      "{'player2': 6, 'drawn': 11, 'player1': 3}\n",
      "()\n",
      "BEST PLAYER VERSION 3\n",
      "{'loss': [2.6112774734497068, 2.6574535255432128, 2.6423331508636476, 2.6179968128204347, 2.635911039352417]}\n",
      "('BEST LOSSES ', 0.31460385488498355, ' ', 2.2518009025115542)\n",
      "('CURRENT LOSSES ', 0.32863139226543192, ' ', 2.3284191555785121)\n",
      "{'player2': 6, 'drawn': 10, 'player1': 4}\n",
      "()\n",
      "BEST PLAYER VERSION 4\n",
      "{'loss': [2.6055786666870118, 2.5736935348510741, 2.5459796047210692, 2.5074543819427491, 2.5002411460876464]}\n",
      "('BEST LOSSES ', 0.30014982096481913, ' ', 2.3269055623004253)\n",
      "('CURRENT LOSSES ', 0.26686636217793225, ' ', 2.2307510706104887)\n",
      "{'player2': 3, 'drawn': 16, 'player1': 1}\n",
      "()\n",
      "BEST PLAYER VERSION 5\n",
      "{'loss': [2.488939384460449, 2.4783461475372315, 2.510974464416504, 2.5458407192230226, 2.5155633277893066]}\n",
      "('BEST LOSSES ', 0.26589389018253456, ' ', 2.2283368111238304)\n",
      "('CURRENT LOSSES ', 0.30420411068955566, ' ', 2.2485004692545867)\n",
      "{'player2': 3, 'drawn': 16, 'player1': 1}\n",
      "()\n",
      "BEST PLAYER VERSION 6\n",
      "{'loss': [2.5207829189300539, 2.4784241085052492, 2.447915853500366, 2.4345479888916017, 2.4427479705810549]}\n",
      "('BEST LOSSES ', 0.27235507530103831, ' ', 2.2492453942988218)\n",
      "('CURRENT LOSSES ', 0.27380092206218348, ' ', 2.2002672312709444)\n",
      "{'player2': 2, 'drawn': 16, 'player1': 2}\n",
      "()\n",
      "BEST PLAYER VERSION 6\n",
      "{'loss': [2.44590163230896, 2.4165599346160889, 2.4360732860565184, 2.4792640933990477, 2.4533378677368165]}\n",
      "('BEST LOSSES ', 0.26784249521123765, ' ', 2.2466920791147662)\n",
      "('CURRENT LOSSES ', 0.27291592103806389, ' ', 2.1866350620624666)\n",
      "{'player2': 1, 'drawn': 17, 'player1': 2}\n",
      "()\n",
      "BEST PLAYER VERSION 6\n",
      "{'loss': [2.437231050491333, 2.4495103073120119, 2.4456259365081787, 2.4240360794067382, 2.4070054092407225]}\n",
      "('BEST LOSSES ', 0.2646353286730535, ' ', 2.2434715258584799)\n",
      "('CURRENT LOSSES ', 0.20803543450063813, ' ', 2.2238587331298918)\n",
      "{'player2': 2, 'drawn': 17, 'player1': 1}\n",
      "()\n",
      "BEST PLAYER VERSION 7\n",
      "{'loss': [2.3615927810668946, 2.3369564609527589, 2.3210801067352294, 2.2993136692047118, 2.3197233219146729]}\n",
      "('BEST LOSSES ', 0.1569076097016853, ' ', 2.1995271048726912)\n",
      "('CURRENT LOSSES ', 0.15892931538546964, ' ', 2.2031290169767015)\n",
      "{'player2': 2, 'drawn': 14, 'player1': 4}\n",
      "()\n",
      "BEST PLAYER VERSION 7\n",
      "{'loss': [2.2910096130371094, 2.2999728450775145, 2.3242184982299805, 2.2756314659118653, 2.2653868789672851]}\n",
      "('BEST LOSSES ', 0.14912740086964488, ' ', 2.1754041070740224)\n",
      "('CURRENT LOSSES ', 0.15391215423447005, ' ', 2.1325835088958218)\n",
      "{'player2': 5, 'drawn': 13, 'player1': 2}\n",
      "()\n",
      "BEST PLAYER VERSION 8\n",
      "{'loss': [2.3356043338775634, 2.3544438304901125, 2.3248761100769042, 2.2865621643066407, 2.2933125267028807]}\n",
      "('BEST LOSSES ', 0.18814301067997585, ' ', 2.1206003741805857)\n",
      "('CURRENT LOSSES ', 0.17334884497821779, ' ', 2.1249887320175835)\n",
      "{'player2': 5, 'drawn': 9, 'player1': 6}\n",
      "()\n",
      "BEST PLAYER VERSION 8\n",
      "{'loss': [2.344573974609375, 2.3843748340606687, 2.3214945468902588, 2.2895056171417236, 2.2948222694396971]}\n",
      "('BEST LOSSES ', 0.18097316628201721, ' ', 2.1229156377341134)\n",
      "('CURRENT LOSSES ', 0.15921301385116576, ' ', 2.1058539469555231)\n",
      "{'player2': 3, 'drawn': 10, 'player1': 7}\n",
      "()\n",
      "BEST PLAYER VERSION 8\n",
      "{'loss': [2.2673715038299562, 2.2756528053283693, 2.2614927501678466, 2.2625515670776366, 2.2676089477539061]}\n",
      "('BEST LOSSES ', 0.17714662279672064, ' ', 2.1150055366433942)\n",
      "('CURRENT LOSSES ', 0.16255724964404919, ' ', 2.1361213174400095)\n",
      "{'player2': 2, 'drawn': 16, 'player1': 2}\n",
      "()\n",
      "BEST PLAYER VERSION 8\n",
      "{'loss': [2.3054607830047606, 2.2912345123291016, 2.2698237857818602, 2.289020803451538, 2.2645849781036378]}\n",
      "('BEST LOSSES ', 0.19681489595049328, ' ', 2.1207720104697811)\n",
      "('CURRENT LOSSES ', 0.17881356367656054, ' ', 2.0821271440313662)\n",
      "{'player2': 1, 'drawn': 13, 'player1': 6}\n",
      "()\n",
      "BEST PLAYER VERSION 8\n",
      "{'loss': [2.2959200019836428, 2.2948544864654541, 2.2798476181030272, 2.2874796352386473, 2.3026289653778078]}\n",
      "('BEST LOSSES ', 0.20951587742387195, ' ', 2.1206869087036786)\n",
      "('CURRENT LOSSES ', 0.20542975651700618, ' ', 2.1245776040944491)\n",
      "{'player2': 0, 'drawn': 16, 'player1': 4}\n",
      "()\n",
      "BEST PLAYER VERSION 8\n",
      "{'loss': [2.3387101020812988, 2.3375640296936036, 2.2908942222595217, 2.3190618724822998, 2.3027740421295166]}\n",
      "('BEST LOSSES ', 0.21141678282896739, ' ', 2.1222812621705764)\n",
      "('CURRENT LOSSES ', 0.19287041326209389, ' ', 2.0929882747920736)\n",
      "{'player2': 4, 'drawn': 11, 'player1': 5}\n",
      "()\n",
      "BEST PLAYER VERSION 8\n",
      "{'loss': [2.3224180488586428, 2.3356209621429445, 2.3340931015014648, 2.3043466186523438, 2.3043755569458009]}\n",
      "('BEST LOSSES ', 0.22268242704023686, ' ', 2.1384441262323564)\n",
      "('CURRENT LOSSES ', 0.21674405007546882, ' ', 2.0829511109074748)\n",
      "{'player2': 5, 'drawn': 9, 'player1': 6}\n",
      "()\n",
      "BEST PLAYER VERSION 8\n",
      "{'loss': [2.3808222694396974, 2.3614929523468016, 2.3560387191772461, 2.3319132080078124, 2.3270168952941894]}\n",
      "('BEST LOSSES ', 0.24438583133855474, ' ', 2.1580355928763106)\n",
      "('CURRENT LOSSES ', 0.22217007605084593, ' ', 2.0830063836888297)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'player2': 9, 'drawn': 8, 'player1': 3}\n",
      "()\n",
      "BEST PLAYER VERSION 9\n",
      "{'loss': [2.4017538223266603, 2.3922939662933351, 2.3793737964630126, 2.3807194519042967, 2.4077372398376466]}\n",
      "('BEST LOSSES ', 0.26749677970636287, ' ', 2.0782874022945279)\n",
      "('CURRENT LOSSES ', 0.26217354643586321, ' ', 2.1467257045910686)\n",
      "{'player2': 9, 'drawn': 8, 'player1': 3}\n",
      "()\n",
      "BEST PLAYER VERSION 10\n",
      "{'loss': [2.5030000991821288, 2.4763555755615236, 2.5249086074829101, 2.4947189674377444, 2.4818353881835939]}\n",
      "('BEST LOSSES ', 0.2987914166690831, ' ', 2.1696255878010304)\n",
      "('CURRENT LOSSES ', 0.3095525754420726, ' ', 2.1504095404585319)\n",
      "{'player2': 9, 'drawn': 5, 'player1': 6}\n",
      "()\n",
      "BEST PLAYER VERSION 11\n",
      "{'loss': [2.4866106395721435, 2.4571442985534668, 2.4672282352447508, 2.4783643321990967, 2.4667911472320556]}\n",
      "('BEST LOSSES ', 0.29980567821666054, ' ', 2.1657133613597286)\n",
      "('CURRENT LOSSES ', 0.29815774095523989, ' ', 2.2026603065101718)\n",
      "{'player2': 4, 'drawn': 8, 'player1': 8}\n",
      "()\n",
      "BEST PLAYER VERSION 11\n",
      "{'loss': [2.4948108539581297, 2.4659948482513427, 2.438655586242676, 2.4442841644287108, 2.4562883033752443]}\n",
      "('BEST LOSSES ', 0.28951095197174559, ' ', 2.1806014273458394)\n",
      "('CURRENT LOSSES ', 0.36877435081818744, ' ', 2.1631177894433837)\n",
      "{'player2': 8, 'drawn': 7, 'player1': 5}\n",
      "()\n",
      "BEST PLAYER VERSION 12\n",
      "{'loss': [2.4781016426086424, 2.4949446334838865, 2.4874049949645998, 2.479004346847534, 2.4584927749633789]}\n",
      "('BEST LOSSES ', 0.3617431664295454, ' ', 2.1858066537336591)\n",
      "('CURRENT LOSSES ', 0.27619723232052878, ' ', 2.169022100585412)\n",
      "{'player2': 4, 'drawn': 13, 'player1': 3}\n",
      "()\n",
      "BEST PLAYER VERSION 13\n",
      "{'loss': [2.5318755111694338, 2.4990078945159913, 2.4873584709167482, 2.5013583660125733, 2.5000904006958007]}\n",
      "('BEST LOSSES ', 0.26896564374089083, ' ', 2.19418310818586)\n",
      "('CURRENT LOSSES ', 0.30205855863956554, ' ', 2.2357402749647068)\n",
      "{'player2': 5, 'drawn': 10, 'player1': 5}\n",
      "()\n",
      "BEST PLAYER VERSION 13\n",
      "{'loss': [2.5479158000946045, 2.5200114727020262, 2.5632999534606933, 2.5969008102416993, 2.5465286102294922]}\n",
      "('BEST LOSSES ', 0.29883763625868576, ' ', 2.2233718400447695)\n",
      "('CURRENT LOSSES ', 0.29731977427910394, ' ', 2.2260336986655456)\n",
      "{'player2': 3, 'drawn': 12, 'player1': 5}\n",
      "()\n",
      "BEST PLAYER VERSION 13\n",
      "{'loss': [2.5576781406402587, 2.5337105960845947, 2.5228011035919189, 2.5325289306640624, 2.5185360012054443]}\n",
      "('BEST LOSSES ', 0.28945581935077036, ' ', 2.2480871359038095)\n",
      "('CURRENT LOSSES ', 0.2900411824540986, ' ', 2.2203682037829413)\n",
      "{'player2': 2, 'drawn': 14, 'player1': 4}\n",
      "()\n",
      "BEST PLAYER VERSION 13\n",
      "{'loss': [2.4853612766265871, 2.4627611751556397, 2.5077653961181641, 2.4738902683258055, 2.4580016403198242]}\n",
      "('BEST LOSSES ', 0.23385854046865753, ' ', 2.2850082497205673)\n",
      "('CURRENT LOSSES ', 0.21533584129494174, ' ', 2.2673939102205143)\n",
      "{'player2': 3, 'drawn': 15, 'player1': 2}\n",
      "()\n",
      "BEST PLAYER VERSION 14\n",
      "{'loss': [2.4830177974700929, 2.4696038856506348, 2.4966700019836425, 2.492837163925171, 2.4881797580718996]}\n",
      "('BEST LOSSES ', 0.19922892779281293, ' ', 2.2724674657749091)\n",
      "('CURRENT LOSSES ', 0.20403003472652734, ' ', 2.2659938751438524)\n",
      "{'player2': 2, 'drawn': 16, 'player1': 2}\n",
      "()\n",
      "BEST PLAYER VERSION 14\n",
      "{'loss': [2.4902215290069578, 2.4899984283447267, 2.4920255985260011, 2.4718958740234376, 2.4542161216735838]}\n",
      "('BEST LOSSES ', 0.22526171138339077, ' ', 2.2760490464295935)\n",
      "('CURRENT LOSSES ', 0.2438449377254103, ' ', 2.2726528027197235)\n",
      "{'player2': 4, 'drawn': 13, 'player1': 3}\n",
      "()\n",
      "BEST PLAYER VERSION 15\n",
      "{'loss': [2.5239195518493651, 2.5323452548980714, 2.4909714221954347, 2.5642244625091553, 2.5580079441070556]}\n",
      "('BEST LOSSES ', 0.26262385916873093, ' ', 2.2743747013620594)\n",
      "('CURRENT LOSSES ', 0.24698078399726844, ' ', 2.2884929832233145)\n",
      "{'player2': 3, 'drawn': 13, 'player1': 4}\n",
      "()\n",
      "BEST PLAYER VERSION 15\n",
      "{'loss': [2.5592643737792971, 2.4986628990173338, 2.5588072280883791, 2.5073102321624754, 2.4776215171813964]}\n",
      "('BEST LOSSES ', 0.23692528487612236, ' ', 2.2747234096682423)\n",
      "('CURRENT LOSSES ', 0.23412425027463427, ' ', 2.2649651260711874)\n",
      "{'player2': 0, 'drawn': 15, 'player1': 5}\n",
      "()\n",
      "BEST PLAYER VERSION 15\n",
      "{'loss': [2.4576442375183105, 2.4485058231353758, 2.4325936756134032, 2.4386107444763185, 2.4470284233093262]}\n",
      "('BEST LOSSES ', 0.23717371390863293, ' ', 2.2694796373538786)\n",
      "('CURRENT LOSSES ', 0.23328457734453059, ' ', 2.2361040500454052)\n",
      "{'player2': 3, 'drawn': 17, 'player1': 0}\n",
      "()\n",
      "BEST PLAYER VERSION 16\n",
      "{'loss': [2.4750857887268065, 2.4698754100799563, 2.4612109394073487, 2.4774817790985106, 2.4930302257537842]}\n",
      "('BEST LOSSES ', 0.21388699382656745, ' ', 2.2269131454072846)\n",
      "('CURRENT LOSSES ', 0.20084736670757886, ' ', 2.1934992731773355)\n",
      "{'player2': 4, 'drawn': 10, 'player1': 6}\n",
      "()\n",
      "BEST PLAYER VERSION 16\n",
      "{'loss': [2.4272921447753908, 2.4308665294647218, 2.4526211719512938, 2.4341001892089844, 2.4070741634368895]}\n",
      "('BEST LOSSES ', 0.20658708432633774, ' ', 2.2203239196680911)\n",
      "('CURRENT LOSSES ', 0.1842298882437941, ' ', 2.2071029228578718)\n",
      "{'player2': 3, 'drawn': 15, 'player1': 2}\n",
      "()\n",
      "BEST PLAYER VERSION 17\n",
      "{'loss': [2.3901581058502197, 2.4140359954833985, 2.4107648200988772, 2.4326258049011229, 2.4027317543029785]}\n",
      "('BEST LOSSES ', 0.19337429938867998, ' ', 2.199511836415871)\n",
      "('CURRENT LOSSES ', 0.20853227124950652, ' ', 2.2356387938710887)\n",
      "{'player2': 0, 'drawn': 15, 'player1': 5}\n",
      "()\n",
      "BEST PLAYER VERSION 17\n",
      "{'loss': [2.4430856704711914, 2.4067400150299072, 2.3860512847900393, 2.3909015846252442, 2.3844366741180418]}\n",
      "('BEST LOSSES ', 0.19223199814830005, ' ', 2.1967094970433063)\n",
      "('CURRENT LOSSES ', 0.21623218752326409, ' ', 2.2003229255829639)\n",
      "{'player2': 4, 'drawn': 11, 'player1': 5}\n",
      "()\n",
      "BEST PLAYER VERSION 17\n",
      "{'loss': [2.4417538547515871, 2.4017296562194823, 2.4435015029907228, 2.4229909896850588, 2.4038773784637453]}\n",
      "('BEST LOSSES ', 0.17557305446254404, ' ', 2.1907791847036808)\n",
      "('CURRENT LOSSES ', 0.23982559201440143, ' ', 2.1926033813461943)\n",
      "{'player2': 4, 'drawn': 7, 'player1': 9}\n",
      "()\n",
      "BEST PLAYER VERSION 17\n",
      "{'loss': [2.4065817756652832, 2.3534457817077636, 2.3840159244537356, 2.3527346191406249, 2.3796406917572019]}\n",
      "('BEST LOSSES ', 0.16626381153839431, ' ', 2.1838510861252236)\n",
      "('CURRENT LOSSES ', 0.20005835601037839, ' ', 2.201237318464274)\n",
      "{'player2': 3, 'drawn': 9, 'player1': 8}\n",
      "()\n",
      "BEST PLAYER VERSION 17\n",
      "{'loss': [2.3735944499969484, 2.3630559196472167, 2.3822272872924803, 2.4060233592987061, 2.3897567062377929]}\n",
      "('BEST LOSSES ', 0.18444030231025693, ' ', 2.1814563279978278)\n",
      "('CURRENT LOSSES ', 0.20218055110006466, ' ', 2.2068268554596049)\n",
      "{'player2': 3, 'drawn': 14, 'player1': 3}\n",
      "()\n",
      "BEST PLAYER VERSION 17\n",
      "{'loss': [2.3950227699279787, 2.3809818992614744, 2.3768180942535402, 2.3443792781829833, 2.380128707885742]}\n",
      "('BEST LOSSES ', 0.20347137707196136, ' ', 2.174616122919546)\n",
      "('CURRENT LOSSES ', 0.21702857577596599, ' ', 2.1624385428546469)\n",
      "{'player2': 1, 'drawn': 15, 'player1': 4}\n",
      "()\n",
      "BEST PLAYER VERSION 17\n",
      "{'loss': [2.422865821838379, 2.4159543628692628, 2.3871369075775148, 2.3771502590179443, 2.3968950595855714]}\n",
      "('BEST LOSSES ', 0.2224935406133606, ' ', 2.1756243846167855)\n",
      "('CURRENT LOSSES ', 0.21392324316924563, ' ', 2.1486135330604328)\n",
      "{'player2': 7, 'drawn': 12, 'player1': 1}\n",
      "()\n",
      "BEST PLAYER VERSION 18\n",
      "{'loss': [2.4120960826873779, 2.4043460006713868, 2.4024274177551268, 2.395829439163208, 2.4193661403656006]}\n",
      "('BEST LOSSES ', 0.22075713393364935, ' ', 2.1492087518483118)\n",
      "('CURRENT LOSSES ', 0.23909678951111762, ' ', 2.1579966235790424)\n",
      "{'player2': 3, 'drawn': 15, 'player1': 2}\n",
      "()\n",
      "BEST PLAYER VERSION 19\n",
      "{'loss': [2.4297968502044678, 2.4412132492065428, 2.4010841426849363, 2.367943084716797, 2.4370990409851072]}\n",
      "('BEST LOSSES ', 0.23790731302009835, ' ', 2.157710386746138)\n",
      "('CURRENT LOSSES ', 0.21553271094149457, ' ', 2.162863668119277)\n",
      "{'player2': 4, 'drawn': 12, 'player1': 4}\n",
      "()\n",
      "BEST PLAYER VERSION 19\n",
      "{'loss': [2.4304898395538328, 2.4432505435943606, 2.3975786380767823, 2.4139598846435546, 2.4177994022369385]}\n",
      "('BEST LOSSES ', 0.25341565466044758, ' ', 2.152312786685171)\n",
      "('CURRENT LOSSES ', 0.2314851953823587, ' ', 2.1212249206931579)\n",
      "{'player2': 3, 'drawn': 15, 'player1': 2}\n",
      "()\n",
      "BEST PLAYER VERSION 20\n",
      "{'loss': [2.3658718662261964, 2.3531527595520019, 2.3861136741638185, 2.3531906852722169, 2.3730714092254637]}\n",
      "('BEST LOSSES ', 0.21532912265404802, ' ', 2.1062754322342996)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('CURRENT LOSSES ', 0.23529137217081561, ' ', 2.1776593586411499)\n",
      "{'player2': 5, 'drawn': 11, 'player1': 4}\n",
      "()\n",
      "BEST PLAYER VERSION 20\n",
      "{'loss': [2.3764586524963378, 2.3655673027038575, 2.3567242240905761, 2.3656366443634034, 2.3659095668792727]}\n",
      "('BEST LOSSES ', 0.2210611953521944, ' ', 2.0905667923384348)\n",
      "('CURRENT LOSSES ', 0.23638181338113001, ' ', 2.1065322523265682)\n",
      "{'player2': 1, 'drawn': 14, 'player1': 5}\n",
      "()\n",
      "BEST PLAYER VERSION 20\n",
      "{'loss': [2.3062339057922365, 2.3263887271881103, 2.2994830970764162, 2.2773650436401369, 2.2759549160003663]}\n",
      "('BEST LOSSES ', 0.19855932204009816, ' ', 2.0807628997275076)\n",
      "('CURRENT LOSSES ', 0.19704921707819914, ' ', 2.0720272848919361)\n",
      "{'player2': 0, 'drawn': 16, 'player1': 4}\n",
      "()\n",
      "BEST PLAYER VERSION 20\n",
      "{'loss': [2.2872521305084228, 2.2475813903808595, 2.2495129394531248, 2.2554239206314088, 2.2687938575744631]}\n",
      "('BEST LOSSES ', 0.18646565888835528, ' ', 2.075277502172769)\n",
      "('CURRENT LOSSES ', 0.23352749213504584, ' ', 2.1327681957289859)\n",
      "{'player2': 2, 'drawn': 17, 'player1': 1}\n",
      "()\n",
      "BEST PLAYER VERSION 21\n",
      "{'loss': [2.2300546875, 2.1749073009490969, 2.1823816757202148, 2.1755900859832762, 2.1837327575683592]}\n",
      "('BEST LOSSES ', 0.18863511343080697, ' ', 2.1417977308063949)\n",
      "('CURRENT LOSSES ', 0.14682087874985825, ' ', 2.0484646820751928)\n",
      "{'player2': 0, 'drawn': 18, 'player1': 2}\n",
      "()\n",
      "BEST PLAYER VERSION 21\n",
      "{'loss': [2.2559645099639893, 2.2950249748229981, 2.284927558898926, 2.2491887073516845, 2.2651168251037599]}\n",
      "('BEST LOSSES ', 0.1919256926016755, ' ', 2.1663836653699788)\n",
      "('CURRENT LOSSES ', 0.14620751585289246, ' ', 2.1018054476447552)\n",
      "{'player2': 4, 'drawn': 12, 'player1': 4}\n",
      "()\n",
      "BEST PLAYER VERSION 21\n",
      "{'loss': [2.2638136749267579, 2.243595579147339, 2.2368180580139159, 2.2485247592926028, 2.2534335975646971]}\n",
      "('BEST LOSSES ', 0.19350542691123329, ' ', 2.2003527358588388)\n",
      "('CURRENT LOSSES ', 0.14347106754867431, ' ', 2.137326694199527)\n",
      "{'player2': 3, 'drawn': 14, 'player1': 3}\n",
      "()\n",
      "BEST PLAYER VERSION 21\n",
      "{'loss': [2.3672829303741456, 2.3330671062469484, 2.3113894290924071, 2.3106116542816162, 2.2974337768554687]}\n",
      "('BEST LOSSES ', 0.21608634325974188, ' ', 2.2437071170429506)\n",
      "('CURRENT LOSSES ', 0.18819970879264228, ' ', 2.1197274220261564)\n",
      "{'player2': 8, 'drawn': 10, 'player1': 2}\n",
      "()\n",
      "BEST PLAYER VERSION 22\n",
      "{'loss': [2.3614773693084716, 2.3642027225494386, 2.3561681327819826, 2.3471732120513917, 2.3448350276947023]}\n",
      "('BEST LOSSES ', 0.20053079260160173, ' ', 2.1582185653221928)\n",
      "('CURRENT LOSSES ', 0.19687060878431767, ' ', 2.1625910162148676)\n",
      "{'player2': 3, 'drawn': 12, 'player1': 5}\n",
      "()\n",
      "BEST PLAYER VERSION 22\n",
      "{'loss': [2.4427151432037353, 2.4492701606750487, 2.4353420562744139, 2.4332297897338866, 2.4410601825714111]}\n",
      "('BEST LOSSES ', 0.22512898119825933, ' ', 2.1998338957555124)\n",
      "('CURRENT LOSSES ', 0.21147732459502686, ' ', 2.2341859249657294)\n",
      "{'player2': 0, 'drawn': 15, 'player1': 5}\n",
      "()\n",
      "BEST PLAYER VERSION 22\n",
      "{'loss': [2.5688981037139893, 2.5384961433410647, 2.5571566238403318, 2.5295044460296632, 2.5621316432952881]}\n",
      "('BEST LOSSES ', 0.28692461128951907, ' ', 2.2332676109739955)\n",
      "('CURRENT LOSSES ', 0.2779839706847651, ' ', 2.2268092769367049)\n",
      "{'player2': 5, 'drawn': 13, 'player1': 2}\n",
      "()\n",
      "BEST PLAYER VERSION 23\n",
      "{'loss': [2.5253931560516358, 2.5318767757415772, 2.5096496868133547, 2.4865106201171874, 2.5161098690032957]}\n",
      "('BEST LOSSES ', 0.27866558395102276, ' ', 2.255387135589991)\n",
      "('CURRENT LOSSES ', 0.27096101998493971, ' ', 2.2828841800861355)\n",
      "{'player2': 3, 'drawn': 12, 'player1': 5}\n",
      "()\n",
      "BEST PLAYER VERSION 23\n",
      "{'loss': [2.6092371482849122, 2.5515290164947508, 2.5576865425109863, 2.5632077980041506, 2.529131544113159]}\n",
      "('BEST LOSSES ', 0.31815098652158669, ' ', 2.2547579151915214)\n",
      "('CURRENT LOSSES ', 0.32945171992947908, ' ', 2.2141985183997752)\n",
      "{'player2': 1, 'drawn': 13, 'player1': 6}\n",
      "()\n",
      "BEST PLAYER VERSION 23\n",
      "{'loss': [2.5417953834533691, 2.5455080242156982, 2.5572692775726318, 2.5354220352172852, 2.5145051822662352]}\n",
      "('BEST LOSSES ', 0.33313815311370082, ' ', 2.255416639890147)\n",
      "('CURRENT LOSSES ', 0.30911284038869241, ' ', 2.2086706706866623)\n",
      "{'player2': 4, 'drawn': 16, 'player1': 0}\n",
      "()\n",
      "BEST PLAYER VERSION 24\n",
      "{'loss': [2.5643976650238036, 2.597806390762329, 2.5953243026733399, 2.5338293380737307, 2.514989532470703]}\n",
      "('BEST LOSSES ', 0.31147157318852547, ' ', 2.1981189602720677)\n",
      "('CURRENT LOSSES ', 0.32171908349927547, ' ', 2.2014043390394069)\n",
      "{'player2': 2, 'drawn': 15, 'player1': 3}\n",
      "()\n",
      "BEST PLAYER VERSION 24\n",
      "{'loss': [2.4700408058166503, 2.464723560333252, 2.4532458896636964, 2.4472528190612794, 2.44217848777771]}\n",
      "('BEST LOSSES ', 0.28367599961085183, ' ', 2.1854432854690162)\n",
      "('CURRENT LOSSES ', 0.27936663902065717, ' ', 2.1783077802157464)\n",
      "{'player2': 6, 'drawn': 10, 'player1': 4}\n",
      "()\n",
      "BEST PLAYER VERSION 25\n",
      "{'loss': [2.5000591125488283, 2.5387905597686768, 2.5212479991912842, 2.5135093803405764, 2.5225884456634522]}\n",
      "('BEST LOSSES ', 0.30177599927122822, ' ', 2.1912392973039827)\n",
      "('CURRENT LOSSES ', 0.30684539700571489, ' ', 2.2180327793762613)\n",
      "{'player2': 2, 'drawn': 15, 'player1': 3}\n",
      "()\n",
      "BEST PLAYER VERSION 25\n",
      "{'loss': [2.5085052433013915, 2.5039196548461913, 2.5169980525970459, 2.4896774654388429, 2.4830083770751954]}\n",
      "('BEST LOSSES ', 0.28935186240158867, ' ', 2.2050809887492346)\n",
      "('CURRENT LOSSES ', 0.33083472009882969, ' ', 2.182857330265541)\n",
      "{'player2': 5, 'drawn': 9, 'player1': 6}\n",
      "()\n",
      "BEST PLAYER VERSION 25\n",
      "{'loss': [2.4982770767211915, 2.4874192085266111, 2.4604668197631834, 2.464839349746704, 2.479417402267456]}\n",
      "('BEST LOSSES ', 0.27629485494887029, ' ', 2.2158587203927604)\n",
      "('CURRENT LOSSES ', 0.28195866912301709, ' ', 2.1944479260946013)\n",
      "{'player2': 3, 'drawn': 14, 'player1': 3}\n",
      "()\n",
      "BEST PLAYER VERSION 25\n",
      "{'loss': [2.5445470981597902, 2.5331769237518311, 2.5466279697418215, 2.5353635730743407, 2.5054755249023439]}\n",
      "('BEST LOSSES ', 0.28765707178279021, ' ', 2.2240086166095416)\n",
      "('CURRENT LOSSES ', 0.29156561429189842, ' ', 2.1895677609438375)\n",
      "{'player2': 5, 'drawn': 10, 'player1': 5}\n",
      "()\n",
      "BEST PLAYER VERSION 25\n",
      "{'loss': [2.5047827415466308, 2.4983489246368409, 2.4784897241592407, 2.5418949432373048, 2.5171476402282713]}\n",
      "('BEST LOSSES ', 0.27576633435556952, ' ', 2.2323266813198561)\n",
      "('CURRENT LOSSES ', 0.28293042994131146, ' ', 2.2075286507454437)\n",
      "{'player2': 2, 'drawn': 14, 'player1': 4}\n",
      "()\n",
      "BEST PLAYER VERSION 25\n",
      "{'loss': [2.4722498321533202, 2.4807962284088134, 2.4803229198455812, 2.4652968730926514, 2.4647763156890869]}\n",
      "('BEST LOSSES ', 0.2525731263338622, ' ', 2.2408735185563229)\n",
      "('CURRENT LOSSES ', 0.27274599999221749, ' ', 2.1731192592901283)\n",
      "{'player2': 6, 'drawn': 9, 'player1': 5}\n",
      "()\n",
      "BEST PLAYER VERSION 25\n",
      "{'loss': [2.4715513935089111, 2.4679383811950681, 2.5003686866760253, 2.4651050338745115, 2.4577400150299074]}\n",
      "('BEST LOSSES ', 0.25032858643435946, ' ', 2.2563542030293151)\n",
      "('CURRENT LOSSES ', 0.25289115152408453, ' ', 2.1709598920806439)\n",
      "{'player2': 6, 'drawn': 9, 'player1': 5}\n",
      "()\n",
      "BEST PLAYER VERSION 25\n",
      "{'loss': [2.4674339923858644, 2.4178820838928221, 2.4583074817657469, 2.4819950618743896, 2.4557437705993652]}\n",
      "('BEST LOSSES ', 0.24934893408647943, ' ', 2.2711866869436501)\n",
      "('CURRENT LOSSES ', 0.25315706564271656, ' ', 2.1914318859783513)\n",
      "{'player2': 2, 'drawn': 8, 'player1': 10}\n",
      "()\n",
      "BEST PLAYER VERSION 25\n",
      "{'loss': [2.4913877544403076, 2.5065774116516115, 2.4951044998168945, 2.4654377784729005, 2.4899441566467284]}\n",
      "('BEST LOSSES ', 0.26742832034939712, ' ', 2.2720130754954142)\n",
      "('CURRENT LOSSES ', 0.25543639251386974, ' ', 2.1943783117566134)\n",
      "{'player2': 3, 'drawn': 14, 'player1': 3}\n",
      "()\n",
      "BEST PLAYER VERSION 25\n",
      "{'loss': [2.453640151977539, 2.4631213455200194, 2.4266088600158691, 2.4237012615203857, 2.4207905445098876]}\n",
      "('BEST LOSSES ', 0.24221342956556602, ' ', 2.268801770228825)\n",
      "('CURRENT LOSSES ', 0.22225477112059247, ' ', 2.1923081501397594)\n",
      "{'player2': 2, 'drawn': 11, 'player1': 7}\n",
      "()\n",
      "BEST PLAYER VERSION 25\n",
      "{'loss': [2.4062857189178466, 2.3971361713409425, 2.3679968585968019, 2.3714779834747315, 2.3742920436859132]}\n",
      "('BEST LOSSES ', 0.19549352852302315, ' ', 2.2716573312573178)\n",
      "('CURRENT LOSSES ', 0.17662340878376873, ' ', 2.2046118225215721)\n",
      "{'player2': 2, 'drawn': 13, 'player1': 5}\n",
      "()\n",
      "BEST PLAYER VERSION 25\n",
      "{'loss': [2.392319164276123, 2.3838171710968017, 2.3863342266082763, 2.3786332969665529, 2.4009957294464113]}\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('BEST LOSSES ', 0.1726360712314578, ' ', 2.2780859574297163)\n",
      "('CURRENT LOSSES ', 0.192117245738713, ' ', 2.2253627240314144)\n",
      "{'player2': 4, 'drawn': 11, 'player1': 5}\n",
      "()\n",
      "BEST PLAYER VERSION 25\n",
      "{'loss': [2.4084902839660645, 2.3719499607086183, 2.3852247371673583, 2.3599228477478027, 2.3401399059295653]}\n",
      "('BEST LOSSES ', 0.16146800124052618, ' ', 2.2768428534373797)\n",
      "('CURRENT LOSSES ', 0.14850474958399576, ' ', 2.1844096748948889)\n",
      "{'player2': 3, 'drawn': 11, 'player1': 6}\n",
      "()\n",
      "BEST PLAYER VERSION 25\n",
      "{'loss': [2.4075229606628419, 2.4202814006805422, 2.4006757259368898, 2.4314981975555421, 2.4211384925842285]}\n",
      "('BEST LOSSES ', 0.19559613782087878, ' ', 2.2736547691216744)\n",
      "('CURRENT LOSSES ', 0.19293282937628045, ' ', 2.1949151282632564)\n",
      "{'player2': 3, 'drawn': 11, 'player1': 6}\n",
      "()\n",
      "BEST PLAYER VERSION 25\n",
      "{'loss': [2.3605380287170412, 2.3416698551177979, 2.3779817581176759, 2.3538286399841311, 2.3606896972656251]}\n",
      "('BEST LOSSES ', 0.16313532585934865, ' ', 2.2789745803935335)\n",
      "('CURRENT LOSSES ', 0.1612608065314434, ' ', 2.1920504429752539)\n",
      "{'player2': 1, 'drawn': 12, 'player1': 7}\n",
      "()\n",
      "BEST PLAYER VERSION 25\n",
      "{'loss': [2.3742286605834959, 2.3392568569183352, 2.3690364246368407, 2.3751393756866457, 2.3689520778656008]}\n",
      "('BEST LOSSES ', 0.16260182665481177, ' ', 2.2836535254237664)\n",
      "('CURRENT LOSSES ', 0.15917562451843031, ' ', 2.2182859673594688)\n",
      "{'player2': 6, 'drawn': 8, 'player1': 6}\n",
      "()\n",
      "BEST PLAYER VERSION 25\n",
      "{'loss': [2.3394853515624998, 2.3298637180328368, 2.3618863792419433, 2.3392214946746828, 2.3223170585632325]}\n",
      "('BEST LOSSES ', 0.14267300655760942, ' ', 2.2814020857868713)\n",
      "('CURRENT LOSSES ', 0.14875594973271503, ' ', 2.1846946991862453)\n",
      "{'player2': 4, 'drawn': 11, 'player1': 5}\n",
      "()\n",
      "BEST PLAYER VERSION 25\n",
      "{'loss': [2.3858892192840577, 2.3764906482696535, 2.3440885581970217, 2.4003117790222168, 2.3732045574188234]}\n",
      "('BEST LOSSES ', 0.16511278275112318, ' ', 2.279862560435483)\n",
      "('CURRENT LOSSES ', 0.17088350874890262, ' ', 2.1975758510878785)\n",
      "{'player2': 3, 'drawn': 11, 'player1': 6}\n",
      "()\n",
      "BEST PLAYER VERSION 25\n",
      "{'loss': [2.3811157455444336, 2.3700830459594728, 2.376643545150757, 2.3667885398864748, 2.3838022632598879]}\n",
      "('BEST LOSSES ', 0.18733181199422561, ' ', 2.274652856652307)\n",
      "('CURRENT LOSSES ', 0.18621180053056857, ' ', 2.1966913345263634)\n",
      "{'player2': 7, 'drawn': 7, 'player1': 6}\n",
      "()\n",
      "BEST PLAYER VERSION 25\n",
      "{'loss': [2.4407942447662352, 2.4467328281402589, 2.4396654148101806, 2.4176462383270265, 2.4245277576446531]}\n",
      "('BEST LOSSES ', 0.22405093082830491, ' ', 2.2675304231788522)\n",
      "('CURRENT LOSSES ', 0.20573864891703095, ' ', 2.2099114044615824)\n",
      "{'player2': 1, 'drawn': 9, 'player1': 10}\n",
      "()\n",
      "BEST PLAYER VERSION 25\n",
      "{'loss': [2.4440011310577394, 2.4557138004302979, 2.4616299629211427, 2.4765573844909667, 2.4653562660217285]}\n",
      "('BEST LOSSES ', 0.2482145513090119, ' ', 2.2713323123695237)\n",
      "('CURRENT LOSSES ', 0.25211315483614272, ' ', 2.2520891906878764)\n",
      "{'player2': 8, 'drawn': 5, 'player1': 7}\n",
      "()\n",
      "BEST PLAYER VERSION 25\n",
      "{'loss': [2.4601420860290526, 2.4773489875793455, 2.4725639209747317, 2.4881024799346925, 2.458596935272217]}\n",
      "('BEST LOSSES ', 0.23643483180498398, ' ', 2.2721292856253332)\n",
      "('CURRENT LOSSES ', 0.23201699018404304, ' ', 2.2204017394718636)\n",
      "{'player2': 7, 'drawn': 8, 'player1': 5}\n",
      "()\n",
      "BEST PLAYER VERSION 26\n",
      "{'loss': [2.5260839786529541, 2.5009395618438721, 2.4867314262390137, 2.511743179321289, 2.4915494079589844]}\n",
      "('BEST LOSSES ', 0.31023523146437054, ' ', 2.2370869457189748)\n",
      "('CURRENT LOSSES ', 0.28471231156929688, ' ', 2.2134065432271885)\n"
     ]
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-67-1295f77f07ac>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m    130\u001b[0m         \u001b[0menv\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprintLosses\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbest_player\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcurrent_player\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    131\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 132\u001b[0;31m         \u001b[0mscores\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0menv\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mplayTournament\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbest_player\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcurrent_player\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mEVAL_EPISODES\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    133\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    134\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/Users/davidfoster/Git/AGI/scripts/gameMetaSquares.pyc\u001b[0m in \u001b[0;36mplayTournament\u001b[0;34m(self, player1, player2, EVAL_EPISODES)\u001b[0m\n\u001b[1;32m    282\u001b[0m                                         \u001b[0maction\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mactionValues\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mplayers\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mstate\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mplayerTurn\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'agent'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mact\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mstate\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    283\u001b[0m                                 \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 284\u001b[0;31m                                         \u001b[0maction\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mactionValues\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mplayers\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mstate\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mplayerTurn\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'agent'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mact\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mstate\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    285\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    286\u001b[0m                                 \u001b[0;31m#print('action', action)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/Users/davidfoster/Git/AGI/scripts/agent.pyc\u001b[0m in \u001b[0;36mact\u001b[0;34m(self, state, tau)\u001b[0m\n\u001b[1;32m    181\u001b[0m                 \u001b[0;32mfor\u001b[0m \u001b[0msim\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mMCTSsimulations\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    182\u001b[0m                         \u001b[0mlogger_agent\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minfo\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'-----STARTING SIMULATION %d ----'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msim\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 183\u001b[0;31m                         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msimulate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    184\u001b[0m                         \u001b[0mlogger_agent\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minfo\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'-----FINISHED SIMULATION %d ----'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msim\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    185\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/Users/davidfoster/Git/AGI/scripts/agent.pyc\u001b[0m in \u001b[0;36msimulate\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m    146\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    147\u001b[0m                 \u001b[0;31m#the value of the leaf for the now 'current' player is therefore -1 (they lost)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 148\u001b[0;31m                 \u001b[0mvalue\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_evaluateLeaf\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mleaf\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mreward\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    149\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    150\u001b[0m                 \u001b[0mlogger_agent\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minfo\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'BREADCRUMBS...%s'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbreadcrumbs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/Users/davidfoster/Git/AGI/scripts/agent.pyc\u001b[0m in \u001b[0;36m_evaluateLeaf\u001b[0;34m(self, leaf, reward, done)\u001b[0m\n\u001b[1;32m    125\u001b[0m                                         \u001b[0mnewNode\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmc\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mNode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnewState\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mprobs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0midx\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    126\u001b[0m                                         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmcts\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0maddNode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnewNode\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 127\u001b[0;31m                                         \u001b[0mlogger_agent\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minfo\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'added node...%s...p = %f'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnewNode\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mid\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mprobs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0midx\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    128\u001b[0m                                         \u001b[0mleaf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mchildIds\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0maction\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnewNode\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mid\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    129\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.pyc\u001b[0m in \u001b[0;36minfo\u001b[0;34m(self, msg, *args, **kwargs)\u001b[0m\n\u001b[1;32m   1165\u001b[0m         \"\"\"\n\u001b[1;32m   1166\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0misEnabledFor\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mINFO\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1167\u001b[0;31m             \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_log\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mINFO\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmsg\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1168\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1169\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0mwarning\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmsg\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.pyc\u001b[0m in \u001b[0;36m_log\u001b[0;34m(self, level, msg, args, exc_info, extra)\u001b[0m\n\u001b[1;32m   1284\u001b[0m                 \u001b[0mexc_info\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0msys\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexc_info\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1285\u001b[0m         \u001b[0mrecord\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmakeRecord\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlevel\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfn\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlno\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmsg\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mexc_info\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfunc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mextra\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1286\u001b[0;31m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhandle\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrecord\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1287\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1288\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0mhandle\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrecord\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.pyc\u001b[0m in \u001b[0;36mhandle\u001b[0;34m(self, record)\u001b[0m\n\u001b[1;32m   1294\u001b[0m         \"\"\"\n\u001b[1;32m   1295\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;32mnot\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdisabled\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfilter\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrecord\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1296\u001b[0;31m             \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcallHandlers\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrecord\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1297\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1298\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0maddHandler\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mhdlr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.pyc\u001b[0m in \u001b[0;36mcallHandlers\u001b[0;34m(self, record)\u001b[0m\n\u001b[1;32m   1334\u001b[0m                 \u001b[0mfound\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfound\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1335\u001b[0m                 \u001b[0;32mif\u001b[0m \u001b[0mrecord\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlevelno\u001b[0m \u001b[0;34m>=\u001b[0m \u001b[0mhdlr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlevel\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1336\u001b[0;31m                     \u001b[0mhdlr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhandle\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrecord\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1337\u001b[0m             \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mc\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpropagate\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1338\u001b[0m                 \u001b[0mc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mNone\u001b[0m    \u001b[0;31m#break out\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.pyc\u001b[0m in \u001b[0;36mhandle\u001b[0;34m(self, record)\u001b[0m\n\u001b[1;32m    757\u001b[0m             \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0macquire\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    758\u001b[0m             \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 759\u001b[0;31m                 \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0memit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrecord\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    760\u001b[0m             \u001b[0;32mfinally\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    761\u001b[0m                 \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrelease\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.pyc\u001b[0m in \u001b[0;36memit\u001b[0;34m(self, record)\u001b[0m\n\u001b[1;32m    955\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstream\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    956\u001b[0m             \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstream\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_open\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 957\u001b[0;31m         \u001b[0mStreamHandler\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0memit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrecord\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    958\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    959\u001b[0m \u001b[0;31m#---------------------------------------------------------------------------\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.pyc\u001b[0m in \u001b[0;36memit\u001b[0;34m(self, record)\u001b[0m\n\u001b[1;32m    883\u001b[0m                 \u001b[0;32mexcept\u001b[0m \u001b[0mUnicodeError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    884\u001b[0m                     \u001b[0mstream\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwrite\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfs\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0mmsg\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mencode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"UTF-8\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 885\u001b[0;31m             \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mflush\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    886\u001b[0m         \u001b[0;32mexcept\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mKeyboardInterrupt\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mSystemExit\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    887\u001b[0m             \u001b[0;32mraise\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.pyc\u001b[0m in \u001b[0;36mflush\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m    843\u001b[0m         \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    844\u001b[0m             \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstream\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mhasattr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstream\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"flush\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 845\u001b[0;31m                 \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstream\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mflush\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    846\u001b[0m         \u001b[0;32mfinally\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    847\u001b[0m             \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrelease\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m: "
     ]
    }
   ],
   "source": [
    "sess = tf.Session()\n",
    "\n",
    "logger_main = setup_logger('logger_main', 'logger_main.log')\n",
    "\n",
    "logger_memory = setup_logger('logger_memory', 'logger_memory.log')\n",
    "\n",
    "logger_main.disabled = False\n",
    "logger_memory.disabled = False\n",
    "\n",
    "logger_main.info('=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*')\n",
    "logger_main.info('=*=*=*=*=*=.      NEW LOG.      =*=*=*=*=*')\n",
    "logger_main.info('=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*')\n",
    "\n",
    "\n",
    "EPISODES = 10\n",
    "\n",
    "EVAL_EPISODES = 20\n",
    "MCTSsimulations = 64\n",
    "\n",
    "MEMORY_SIZE = 24 * 8 * EPISODES * 5\n",
    "\n",
    "BATCH_SIZE = 2000\n",
    "\n",
    "env = game.make('XO', MEMORY_SIZE)\n",
    "\n",
    "pieces = {'1':'X', '0': '-', '-1':'O'}\n",
    "\n",
    "state_size = len(env.gameState.binary())\n",
    "action_size = len(env.actionSpace)\n",
    "\n",
    "current_player = agent.Agent(state_size, action_size, MCTSsimulations)\n",
    "best_player = agent.Agent(state_size, action_size, MCTSsimulations)  #100\n",
    "\n",
    "best_players = [best_player]\n",
    "best_player_version = 0\n",
    "\n",
    "##### SELF PLAY\n",
    "\n",
    "while 1:\n",
    "\n",
    "    #current_player = player_list[len(player_list) - 1]\n",
    "    #best_player = player_list[best_player_num]\n",
    "\n",
    "    logger_main.info('BEST PLAYER VERSION: %d', best_player_version)\n",
    "    print('BEST PLAYER VERSION ' + str(best_player_version))\n",
    "\n",
    "    scores = {\"best_player\":0, \"drawn\": 0, \"current_player\":0}\n",
    "\n",
    "    for e in range(EPISODES):\n",
    "        logger_main.info('====================')\n",
    "        logger_main.info('EPISODE %d OF %d', e+1, EPISODES)\n",
    "        logger_main.info('====================')\n",
    "        \n",
    "#       print('EPISODE ' + str(e+1))\n",
    "\n",
    "        state = env.reset()\n",
    "        done = 0\n",
    "        turn = 0\n",
    "#         if best_player.mcts == None:\n",
    "#             print('BEST PLAYER MCTS: ' + '0')\n",
    "#         else:\n",
    "#             print('BEST PLAYER MCTS: ' + str(len(best_player.mcts)))\n",
    "        \n",
    "#         if best_player.mcts == None:\n",
    "#             print('CURRENT PLAYER MCTS: ' + '0' )\n",
    "#         else:\n",
    "#             print('CURRENT PLAYER MCTS: ' + str(len(current_player.mcts)))\n",
    "        \n",
    "        while done == 0:\n",
    "            turn = turn + 1\n",
    "            # env.render()\n",
    "            for r in range(5):\n",
    "                logger_main.info(state.board[4*r : (4*r + 4)])\n",
    "\n",
    "\n",
    "            #### Run the MCTS algo and return an action\n",
    "            if turn < 5:\n",
    "                action, pi = best_player.act(state, 1)\n",
    "            else:\n",
    "                action, pi = best_player.act(state, 0)\n",
    "\n",
    "            logger_main.info('action: %d', action)\n",
    "            logger_main.info('pi: %s', pi)\n",
    "\n",
    "            ####Commit the move to memory\n",
    "            env.remember(state, pi)\n",
    "\n",
    "            #### Do the action\n",
    "            next_state, reward, done, _ = env.step(action)\n",
    "\n",
    "            if done == 1:\n",
    "\n",
    "                #### If the game is finished, get the reward\n",
    "                for move in env.stmemory:\n",
    "                    if move[3] == state.playerTurn:\n",
    "                        move.append(reward)\n",
    "                    else:\n",
    "                        move.append(-reward)\n",
    "                        \n",
    "                logger_memory.info('====================')\n",
    "                logger_memory.info('ADDING NEW MEMORIES')\n",
    "                logger_memory.info('====================')\n",
    "                for s in env.stmemory:\n",
    "                    logger_memory.info('NEW MEMORY: %s', s)\n",
    "\n",
    "                best_player.mcts = None\n",
    "\n",
    "                env.commit_stmemory()\n",
    "\n",
    "\n",
    "\n",
    "            else:\n",
    "                ### Switch to the next state\n",
    "                state = next_state\n",
    "                logger_main.info('board %s', state.board)\n",
    "\n",
    "\n",
    "    #print('retraining...')  \n",
    "    logger_memory.info('====================')\n",
    "    logger_memory.info('CURRENT MEMORY SIZE')\n",
    "    logger_memory.info('====================')\n",
    "    logger_memory.info(len(env.memory))\n",
    "\n",
    "    if len(env.memory) == env.MEMORY_SIZE:\n",
    "        current_player.replay(BATCH_SIZE, env.memory)\n",
    "\n",
    "        current_player.mcts = None\n",
    "        best_player.mcts = None\n",
    "\n",
    "        env.printLosses(best_player, current_player)\n",
    "\n",
    "        scores = env.playTournament(best_player, current_player, EVAL_EPISODES)\n",
    "\n",
    "\n",
    "        print(scores)\n",
    "        print()\n",
    "\n",
    "        if scores['player2'] > scores['player1'] * 1.3:\n",
    "            best_player_version = best_player_version + 1\n",
    "            best_model = clone_model(current_player.model)\n",
    "            best_model.set_weights(current_player.model.get_weights())\n",
    "            best_player = agent.Agent(state_size, action_size, MCTSsimulations)\n",
    "            best_player.model = best_model\n",
    "            best_players.append(best_player)\n",
    "            #env.memory = deque(maxlen=env.MEMORY_SIZE)\n",
    "    else:\n",
    "        print('MEMORY LENGTH: ', len(env.memory))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'player2': 29, 'drawn': 52, 'player1': 19}\n"
     ]
    }
   ],
   "source": [
    "EVAL_EPISODES = 100\n",
    "new_player = agent.Agent(state_size, action_size, MCTSsimulations)\n",
    "scores = env.playTournament(best_player, new_player, EVAL_EPISODES)\n",
    "print(scores)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 0.07033837  0.19895889  0.05025684  0.04956389  0.07613768  0.08492783\n",
      "  0.03984782  0.22977298  0.10538718  0.07709356]\n",
      "[ 0  1  2  3  6  7 10 12 14 15]\n",
      "[[12]]\n"
     ]
    }
   ],
   "source": [
    "board = [0 ,  0,  0,  0,\n",
    "         1 , -1,  0,  0,\n",
    "         -1, -1,  0,  1,\n",
    "         0 , 1 ,  0,  0\n",
    "        ]\n",
    "currentPlayer = 1\n",
    "answer = 2\n",
    "state = game.GameState(np.array(board, dtype=np.int), currentPlayer)\n",
    "inputToModel = np.array([state.convertToModelInput()])\n",
    "preds = best_player.model.predict(inputToModel)[0]\n",
    "\n",
    "logits = preds[1:]\n",
    "odds = np.exp(logits)\n",
    "probs = odds / np.sum(odds)\n",
    "\n",
    "allowedActions = state.allowedActions()\n",
    "probs = probs[allowedActions]\n",
    "\n",
    "guess = np.argwhere(probs == max(probs))\n",
    "\n",
    "print(probs)\n",
    "print(allowedActions)\n",
    "print(allowedActions[guess])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "Error when checking : expected conv2d_2_input to have 4 dimensions, but got array with shape (2, 3, 3)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-4-a7594da67250>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mbest_player\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtakeExam\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;32m/Users/davidfoster/Git/AGI/scripts/agent.pyc\u001b[0m in \u001b[0;36mtakeExam\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m    306\u001b[0m \t\t]\n\u001b[1;32m    307\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 308\u001b[0;31m                 \u001b[0;32mfor\u001b[0m \u001b[0mq\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mquestions\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    309\u001b[0m                         \u001b[0mq_result\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mq_guess\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtakeQuestion\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mq\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mq\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mq\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    310\u001b[0m                         \u001b[0mscore\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mscore\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mq_result\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/Users/davidfoster/Git/AGI/scripts/agent.pyc\u001b[0m in \u001b[0;36mtakeQuestion\u001b[0;34m(self, board, currentPlayer, answers)\u001b[0m\n\u001b[1;32m    317\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    318\u001b[0m                 \u001b[0mstate\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mgame\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mGameState\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0marray\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mboard\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mint\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcurrentPlayer\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 319\u001b[0;31m                 \u001b[0minputToModel\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mstate\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconvertToModelInput\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    320\u001b[0m                 \u001b[0mpreds\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpredict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minputToModel\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    321\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/keras/models.pyc\u001b[0m in \u001b[0;36mpredict\u001b[0;34m(self, x, batch_size, verbose)\u001b[0m\n\u001b[1;32m    911\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbuilt\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    912\u001b[0m             \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbuild\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 913\u001b[0;31m         \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpredict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbatch_size\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mbatch_size\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mverbose\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mverbose\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    914\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    915\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0mpredict_on_batch\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/keras/engine/training.pyc\u001b[0m in \u001b[0;36mpredict\u001b[0;34m(self, x, batch_size, verbose, steps)\u001b[0m\n\u001b[1;32m   1693\u001b[0m         x = _standardize_input_data(x, self._feed_input_names,\n\u001b[1;32m   1694\u001b[0m                                     \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_feed_input_shapes\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1695\u001b[0;31m                                     check_batch_axis=False)\n\u001b[0m\u001b[1;32m   1696\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstateful\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1697\u001b[0m             \u001b[0;32mif\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m>\u001b[0m \u001b[0mbatch_size\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0mbatch_size\u001b[0m \u001b[0;34m!=\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/keras/engine/training.pyc\u001b[0m in \u001b[0;36m_standardize_input_data\u001b[0;34m(data, names, shapes, check_batch_axis, exception_prefix)\u001b[0m\n\u001b[1;32m    130\u001b[0m                                  \u001b[0;34m' to have '\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mshapes\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m+\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    131\u001b[0m                                  \u001b[0;34m' dimensions, but got array with shape '\u001b[0m \u001b[0;34m+\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 132\u001b[0;31m                                  str(array.shape))\n\u001b[0m\u001b[1;32m    133\u001b[0m             \u001b[0;32mfor\u001b[0m \u001b[0mj\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mdim\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mref_dim\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32min\u001b[0m \u001b[0menumerate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mzip\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0marray\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mshapes\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    134\u001b[0m                 \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mj\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mcheck_batch_axis\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mValueError\u001b[0m: Error when checking : expected conv2d_2_input to have 4 dimensions, but got array with shape (2, 3, 3)"
     ]
    }
   ],
   "source": [
    "best_player.takeExam()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(2, array([ 0.,  0.,  1.,  0.,  0.,  0.,  0.,  0.,  0.]))\n",
      "{'Q': 0.98623503595590589, 'P': 1, 'W': 39.449401438236237, 'N': 40}\n",
      "[array([1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0])]\n"
     ]
    }
   ],
   "source": [
    "\n",
    "print(current_player.act(state, 0))\n",
    "print(current_player.mcts.tree[state.convertStateToId()].stats)\n",
    "\n",
    "#print(best_player.act(state, 0))\n",
    "\n",
    "print(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "22"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(best_player.mcts)\n",
    "len(current_player.mcts)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "LOSSES\n",
      "3.13525017795\n",
      "0.870526376158\n",
      "2.26472380179\n",
      "------\n",
      "0.875415976207\n",
      "PI\n",
      "[[ 0.1010101   0.12121212  0.1010101  ...,  0.1010101   0.1010101\n",
      "   0.13131313]\n",
      " [ 0.1010101   0.11111111  0.1010101  ...,  0.13131313  0.11111111\n",
      "   0.1010101 ]\n",
      " [ 0.13131313  0.1010101   0.1010101  ...,  0.1010101   0.12121212\n",
      "   0.1010101 ]\n",
      " ..., \n",
      " [ 0.          0.          0.96045198 ...,  0.02259887  0.01694915  0.        ]\n",
      " [ 0.02259887  0.          0.         ...,  0.          0.          0.96045198]\n",
      " [ 0.          0.01694915  0.02259887 ...,  0.96045198  0.          0.        ]]\n",
      "PROBS\n",
      "[[ 0.1083045   0.11030342  0.10945559 ...,  0.11207842  0.11971595\n",
      "   0.11085337]\n",
      " [ 0.1083045   0.11030342  0.10945559 ...,  0.11207842  0.11971595\n",
      "   0.11085337]\n",
      " [ 0.1083045   0.11030342  0.10945559 ...,  0.11207842  0.11971595\n",
      "   0.11085337]\n",
      " ..., \n",
      " [ 0.08188468  0.12271193  0.09904243 ...,  0.09753785  0.12103736\n",
      "   0.10803305]\n",
      " [ 0.0427911   0.07212256  0.11233814 ...,  0.12501495  0.25944976\n",
      "   0.039162  ]\n",
      " [ 0.06784247  0.12871168  0.10488583 ...,  0.13192028  0.1672409\n",
      "   0.06691065]]\n",
      "DIFF\n",
      "[[  7.29439741e-03   1.09087001e-02   8.44549091e-03 ...,   1.10683149e-02\n",
      "    1.87058517e-02   2.04597568e-02]\n",
      " [  7.29439741e-03   8.07690046e-04   8.44549091e-03 ...,   1.92347154e-02\n",
      "    8.60484157e-03   9.84327348e-03]\n",
      " [  2.30086329e-02   9.29332006e-03   8.44549091e-03 ...,   1.10683149e-02\n",
      "    1.49616853e-03   9.84327348e-03]\n",
      " ..., \n",
      " [  8.18846829e-02   1.22711929e-01   8.61409545e-01 ...,   7.49389847e-02\n",
      "    1.04088211e-01   1.08033050e-01]\n",
      " [  2.01922336e-02   7.21225599e-02   1.12338142e-01 ...,   1.25014947e-01\n",
      "    2.59449761e-01   9.21289980e-01]\n",
      " [  6.78424679e-02   1.11762527e-01   8.22869604e-02 ...,   8.28531697e-01\n",
      "    1.67240900e-01   6.69106464e-02]]\n",
      "------\n"
     ]
    }
   ],
   "source": [
    "import itertools\n",
    "\n",
    "import tensorflow as tf\n",
    "from loss import cemse\n",
    "from keras import losses\n",
    "\n",
    "#data = list(itertools.islice(env.memory, 0, 73))\n",
    "data = env.memory\n",
    "\n",
    "sess = tf.Session()\n",
    "\n",
    "preds = best_player.predict(np.array([e[0] for e in data]))\n",
    "\n",
    "y_true = tf.constant(np.array([np.append(m[3], m[1]) for m in data]), dtype='float64')\n",
    "y_pred = tf.constant(preds, dtype='float64')\n",
    "\n",
    "#print('Y_TRUE')\n",
    "#print(sess.run(y_true))\n",
    "#print('Y_PRED')\n",
    "#print(sess.run(y_pred))\n",
    "\n",
    "v = tf.slice(y_pred, [0,0], [-1,1])\n",
    "z = tf.slice(y_true, [0,0], [-1,1])\n",
    "\n",
    "#print('TANH VALUE')\n",
    "#print(sess.run(tf.tanh(v)))\n",
    "#print('ACTUAL WINNER')\n",
    "#print(sess.run(z))\n",
    "\n",
    "p = tf.slice(y_pred, [0,1], [-1,-1])\n",
    "pi = tf.slice(y_true, [0,1], [-1,-1])\n",
    "\n",
    "#print('EXP LOGIT')\n",
    "#print(sess.run(tf.exp(p)/ tf.reduce_sum(tf.exp(p), axis = 1, keep_dims = True)))\n",
    "#print('ACTUAL PI')\n",
    "#print(sess.run(pi))\n",
    "\n",
    "\n",
    "\n",
    "loss1 = losses.mean_squared_error(z, tf.tanh(v))\n",
    "loss2 = tf.nn.softmax_cross_entropy_with_logits(labels = pi, logits = p)\n",
    "\n",
    "loss = cemse(y_true, y_pred)\n",
    "\n",
    "\n",
    "total_loss = tf.reduce_mean(loss)\n",
    "total_loss1 = tf.reduce_mean(loss1)\n",
    "total_loss2 = tf.reduce_mean(loss2)\n",
    "\n",
    "print('LOSSES')\n",
    "#print(sess.run(loss))\n",
    "#print(sess.run(loss1))\n",
    "#print(sess.run(loss2))\n",
    "\n",
    "print(sess.run(total_loss))\n",
    "print(sess.run(total_loss1))\n",
    "print(sess.run(total_loss2))\n",
    "\n",
    "print('------')\n",
    "\n",
    "print(sess.run(tf.reduce_mean(tf.abs(z - tf.tanh(v)))))\n",
    "print('PI')\n",
    "print(sess.run(pi))\n",
    "print('PROBS')\n",
    "print(sess.run(tf.exp(p)/ tf.reduce_sum(tf.exp(p), axis = 1, keep_dims = True) ))\n",
    "print('DIFF')\n",
    "print(sess.run(tf.abs(pi - (tf.exp(p)/ tf.reduce_sum(tf.exp(p), axis = 1, keep_dims = True) ))))\n",
    "\n",
    "print('------')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[  4.53334796e-33   5.81732687e-13  -3.86682540e-33 ...,  -5.40781081e-01\n",
      "    3.26880666e-34   6.35292157e-34]\n",
      " [ -2.20267070e-33   6.27952168e-33  -4.43489498e-34 ...,  -4.57695782e-01\n",
      "    5.72786071e-33   6.04115346e-33]\n",
      " [  8.16251155e-33  -5.86191482e-33   2.46428468e-33 ...,  -2.89294213e-01\n",
      "   -5.76195776e-33   5.19415983e-33]\n",
      " ..., \n",
      " [ -2.85691725e-33   4.06086095e-33   9.45636055e-33 ...,   2.10732326e-01\n",
      "    5.09414583e-33   1.01765455e-32]\n",
      " [  1.36634614e-33  -1.33011631e-33  -9.42883121e-34 ...,   1.70899644e-01\n",
      "   -1.10015228e-34   8.16319040e-33]\n",
      " [  4.45795396e-34  -4.07285834e-33  -3.60237995e-33 ...,   2.44420812e-01\n",
      "   -7.62906046e-33   9.07550332e-33]]\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAACOCAYAAAAhHfOYAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAFTtJREFUeJzt3Xt0HNV9B/Dvz9KudiVZD0u2kF/I\nBvNwQjFgXgdCKI9T0pCaFhpCC3VdUp+TkhQSWjD80ZKe5iSkCZDT09L6AMWcQ6EUSKE0QME4YCgQ\nm0d52BiDg7GMLMu2ZL1XWunXP3Y8d0bdWc3OrnaH2e/nHB/fu3M1ezUzezX7m/sQVQUREX3+zSp3\nB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NfFfLYAu\nVOB1EVQpG/QFAPY48hU7h7qIdCAzncLrANpU9chCkvsAtJWpWqV2F4CbAByZnagFlTnH/hIAPQD+\nxQo/3SMidajA60JV9wL4CYBPkWnIDwN4A5V5XQTCh6IlJiL1AB4DcIOq9ju3WatDRb7bkYhcCmC/\nqr5R7rqEQDWAUwHcraqnIDM1hiu8UkHXRTMy30yWAJgPoA7AJWWt1OdMKRv0vQAWOfKec6hHlYjE\nkGnMH1TVI3OcdotIu7W9HZlVoaLuHAC/IyKfIBN6uwCZOLKvOfYjphNAp6q+buUfRaaBr8Tr4iIA\nv1bVHlUdB/A4MtdKJV4XgZSyQd8CYJn1xDqOzMOOJ0v4/mVlxYjvBbBdVe9wbHoSmfnkgQqZV15V\nb1HVharagcx18IKq/iHMHPtA5RyLfQD2iMjx1ksXAtiGCrwukAm1nCUitdbn5cixqLjrIqhSz7b4\n28jETqsA3KeqPyjZm5eZiJwLYDOAd2HixrciE0d/BMBiALsBfF1VD5WlkmUgIucD+AtVvVREliJz\nxz4HmTn2r1bVVK6fjwIRWYHMw+E4gF0A1sBaewAVdl2IyPcBXIlMr7C3AHwTmZh5xV0XQXCkKBFR\nRPChKBFRRLBBJyKKCDboREQRwQadiCgi2KATEUUEG3Qioohgg05EFBFs0ImIIuL/AO5e9Sd9dVM+\nAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x123ae0690>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEoAAAD8CAYAAADQQzIZAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAACzJJREFUeJztnX1sXWUZwH9P7+332m3dxljXwWZo\nwAUCIxMmfiWgCQI6/0DDQggx0/2jy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DADQva46WTwDw0GVPZeqs\ne+32cJxo4i4r3qOM+HM9f65XXFyUERdlxEUZcVFGXJQRF2XERRlxUUZclBEXZcRFGXFRRlyUERdl\nxEUZcVFGXJQRF2XERRlxUUZclBEXZWRK5j2I5ywfGUpnNsWzTG95cCsA1z28AoDB3vAEuXdPmKeg\n8dK67O6iJ8TxRIFxdGdjS3iqvPehEAn6vm+uyNQ58Xa0nyXZedEteI8y4qKM+CN1f6ReXFyUERdl\npKRjlIh0EbKAHJ2E3c+d4H4vVtVxp3EsqSgAEdlmGTzLZb8x/tUz4qKMTIWo9efYfoEpGKPOVfyr\nZ6RkokTkRhHZEwVrTzgXn4g8KSKdIrIjZ92kJ0UsiSgRSQA/Bj4JLAVWicjSCe7uKcZGoE56UsRS\n9ahrgP2qekBVh4DnCOG3eaOqrwA9p62e9KSIpRK1EDics/yewdoTJO+kiPky7QbzsyVFLIRSiXoH\nWJSzXOxg7Y4oGSJnS4pYCKUStRVojaYpqSLMxPFCEfc/+UkRVbUkf4CbgL3AW8D9BeznWcJEFcOE\nsW41Ifj7RWAf8Begqdjt9zNzI9NuMJ8sXJQRF2XERRlxUUZclBEXZcRFGfk/8wU3Wy/Zz9EAAAAA\nSUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x160c5e7d0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "l1 = current_player.model.layers[0].get_weights()[0]\n",
    "print(l1)\n",
    "plt.imshow(l1, cmap='coolwarm', interpolation='nearest')\n",
    "plt.show()\n",
    "\n",
    "\n",
    "l2 = current_player.model.layers[1].get_weights()[0]\n",
    "plt.imshow(l2, cmap='coolwarm', interpolation='nearest')\n",
    "plt.show()\n",
    "\n",
    "# l3 = current_player.model.layers[2].get_weights()[0]\n",
    "# plt.imshow(l3, cmap='coolwarm', interpolation='nearest')\n",
    "# plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "ename": "FailedPreconditionError",
     "evalue": "Attempting to use uninitialized value dense_4/kernel\n\t [[Node: dense_4/kernel/read = Identity[T=DT_FLOAT, _class=[\"loc:@dense_4/kernel\"], _device=\"/job:localhost/replica:0/task:0/device:CPU:0\"](dense_4/kernel)]]\n\nCaused by op u'dense_4/kernel/read', defined at:\n  File \"/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py\", line 174, in _run_module_as_main\n    \"__main__\", fname, loader, pkg_name)\n  File \"/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py\", line 72, in _run_code\n    exec code in run_globals\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/ipykernel_launcher.py\", line 16, in <module>\n    app.launch_new_instance()\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/traitlets/config/application.py\", line 658, in launch_instance\n    app.start()\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/ipykernel/kernelapp.py\", line 477, in start\n    ioloop.IOLoop.instance().start()\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/zmq/eventloop/ioloop.py\", line 177, in start\n    super(ZMQIOLoop, self).start()\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/tornado/ioloop.py\", line 888, in start\n    handler_func(fd_obj, events)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/tornado/stack_context.py\", line 277, in null_wrapper\n    return fn(*args, **kwargs)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/zmq/eventloop/zmqstream.py\", line 440, in _handle_events\n    self._handle_recv()\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/zmq/eventloop/zmqstream.py\", line 472, in _handle_recv\n    self._run_callback(callback, msg)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/zmq/eventloop/zmqstream.py\", line 414, in _run_callback\n    callback(*args, **kwargs)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/tornado/stack_context.py\", line 277, in null_wrapper\n    return fn(*args, **kwargs)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/ipykernel/kernelbase.py\", line 283, in dispatcher\n    return self.dispatch_shell(stream, msg)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/ipykernel/kernelbase.py\", line 235, in dispatch_shell\n    handler(stream, idents, msg)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/ipykernel/kernelbase.py\", line 399, in execute_request\n    user_expressions, allow_stdin)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/ipykernel/ipkernel.py\", line 196, in do_execute\n    res = shell.run_cell(code, store_history=store_history, silent=silent)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/ipykernel/zmqshell.py\", line 533, in run_cell\n    return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/IPython/core/interactiveshell.py\", line 2718, in run_cell\n    interactivity=interactivity, compiler=compiler, result=result)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/IPython/core/interactiveshell.py\", line 2822, in run_ast_nodes\n    if self.run_code(code, result):\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/IPython/core/interactiveshell.py\", line 2882, in run_code\n    exec(code_obj, self.user_global_ns, self.user_ns)\n  File \"<ipython-input-3-ed082c4f0622>\", line 26, in <module>\n    best_player = agent.Agent(state_size, action_size, MCTSsimulations)\n  File \"agent.py\", line 33, in __init__\n    self.model = self._build_model(model)\n  File \"agent.py\", line 44, in _build_model\n    model.add(Dense(10, use_bias=True, bias_initializer='random_uniform', activation='relu', kernel_regularizer=regularizers.l2(0.00001), input_dim=self.state_size))\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/keras/models.py\", line 442, in add\n    layer(x)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/keras/engine/topology.py\", line 575, in __call__\n    self.build(input_shapes[0])\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/keras/layers/core.py\", line 828, in build\n    constraint=self.kernel_constraint)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/keras/legacy/interfaces.py\", line 87, in wrapper\n    return func(*args, **kwargs)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/keras/engine/topology.py\", line 399, in add_weight\n    constraint=constraint)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py\", line 316, in variable\n    v = tf.Variable(value, dtype=_convert_string_dtype(dtype), name=name)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/tensorflow/python/ops/variables.py\", line 213, in __init__\n    constraint=constraint)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/tensorflow/python/ops/variables.py\", line 360, in _init_from_args\n    self._snapshot = array_ops.identity(self._variable, name=\"read\")\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/tensorflow/python/ops/array_ops.py\", line 125, in identity\n    return gen_array_ops.identity(input, name=name)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/tensorflow/python/ops/gen_array_ops.py\", line 2108, in identity\n    \"Identity\", input=input, name=name)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py\", line 787, in _apply_op_helper\n    op_def=op_def)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/tensorflow/python/framework/ops.py\", line 2991, in create_op\n    op_def=op_def)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/tensorflow/python/framework/ops.py\", line 1479, in __init__\n    self._traceback = self._graph._extract_stack()  # pylint: disable=protected-access\n\nFailedPreconditionError (see above for traceback): Attempting to use uninitialized value dense_4/kernel\n\t [[Node: dense_4/kernel/read = Identity[T=DT_FLOAT, _class=[\"loc:@dense_4/kernel\"], _device=\"/job:localhost/replica:0/task:0/device:CPU:0\"](dense_4/kernel)]]\n",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mFailedPreconditionError\u001b[0m                   Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-16-1e8675135d4f>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0;31m###### QUESTION 1 #########\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      2\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbest_player_version\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m     \u001b[0mpreds\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mbest_players\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpredict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0marray\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mint\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      4\u001b[0m     \u001b[0;32mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mround\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpreds\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      5\u001b[0m     \u001b[0;32mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mround\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexp\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m/\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexp\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mpreds\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/Users/davidfoster/Git/AGI/scripts/agent.pyc\u001b[0m in \u001b[0;36mpredict\u001b[0;34m(self, inputToModel)\u001b[0m\n\u001b[1;32m    225\u001b[0m         \u001b[0;32mdef\u001b[0m \u001b[0mpredict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minputToModel\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    226\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 227\u001b[0;31m                 \u001b[0mpreds\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpredict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minputToModel\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    228\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    229\u001b[0m                 \u001b[0;32mreturn\u001b[0m \u001b[0mpreds\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/keras/models.pyc\u001b[0m in \u001b[0;36mpredict\u001b[0;34m(self, x, batch_size, verbose)\u001b[0m\n\u001b[1;32m    911\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbuilt\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    912\u001b[0m             \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbuild\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 913\u001b[0;31m         \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpredict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbatch_size\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mbatch_size\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mverbose\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mverbose\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    914\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    915\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0mpredict_on_batch\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/keras/engine/training.pyc\u001b[0m in \u001b[0;36mpredict\u001b[0;34m(self, x, batch_size, verbose, steps)\u001b[0m\n\u001b[1;32m   1711\u001b[0m         \u001b[0mf\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpredict_function\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1712\u001b[0m         return self._predict_loop(f, ins, batch_size=batch_size,\n\u001b[0;32m-> 1713\u001b[0;31m                                   verbose=verbose, steps=steps)\n\u001b[0m\u001b[1;32m   1714\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1715\u001b[0m     def train_on_batch(self, x, y,\n",
      "\u001b[0;32m/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/keras/engine/training.pyc\u001b[0m in \u001b[0;36m_predict_loop\u001b[0;34m(self, f, ins, batch_size, verbose, steps)\u001b[0m\n\u001b[1;32m   1267\u001b[0m                 \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1268\u001b[0m                     \u001b[0mins_batch\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_slice_arrays\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mins\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbatch_ids\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1269\u001b[0;31m                 \u001b[0mbatch_outs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mins_batch\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1270\u001b[0m                 \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbatch_outs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlist\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1271\u001b[0m                     \u001b[0mbatch_outs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mbatch_outs\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/keras/backend/tensorflow_backend.pyc\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, inputs)\u001b[0m\n\u001b[1;32m   2271\u001b[0m         updated = session.run(self.outputs + [self.updates_op],\n\u001b[1;32m   2272\u001b[0m                               \u001b[0mfeed_dict\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mfeed_dict\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2273\u001b[0;31m                               **self.session_kwargs)\n\u001b[0m\u001b[1;32m   2274\u001b[0m         \u001b[0;32mreturn\u001b[0m \u001b[0mupdated\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0moutputs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   2275\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/tensorflow/python/client/session.pyc\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self, fetches, feed_dict, options, run_metadata)\u001b[0m\n\u001b[1;32m    887\u001b[0m     \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    888\u001b[0m       result = self._run(None, fetches, feed_dict, options_ptr,\n\u001b[0;32m--> 889\u001b[0;31m                          run_metadata_ptr)\n\u001b[0m\u001b[1;32m    890\u001b[0m       \u001b[0;32mif\u001b[0m \u001b[0mrun_metadata\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    891\u001b[0m         \u001b[0mproto_data\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtf_session\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mTF_GetBuffer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrun_metadata_ptr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/tensorflow/python/client/session.pyc\u001b[0m in \u001b[0;36m_run\u001b[0;34m(self, handle, fetches, feed_dict, options, run_metadata)\u001b[0m\n\u001b[1;32m   1118\u001b[0m     \u001b[0;32mif\u001b[0m \u001b[0mfinal_fetches\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0mfinal_targets\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mhandle\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mfeed_dict_tensor\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1119\u001b[0m       results = self._do_run(handle, final_targets, final_fetches,\n\u001b[0;32m-> 1120\u001b[0;31m                              feed_dict_tensor, options, run_metadata)\n\u001b[0m\u001b[1;32m   1121\u001b[0m     \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1122\u001b[0m       \u001b[0mresults\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/tensorflow/python/client/session.pyc\u001b[0m in \u001b[0;36m_do_run\u001b[0;34m(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)\u001b[0m\n\u001b[1;32m   1315\u001b[0m     \u001b[0;32mif\u001b[0m \u001b[0mhandle\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1316\u001b[0m       return self._do_call(_run_fn, self._session, feeds, fetches, targets,\n\u001b[0;32m-> 1317\u001b[0;31m                            options, run_metadata)\n\u001b[0m\u001b[1;32m   1318\u001b[0m     \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1319\u001b[0m       \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_do_call\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0m_prun_fn\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_session\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mhandle\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfeeds\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfetches\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/tensorflow/python/client/session.pyc\u001b[0m in \u001b[0;36m_do_call\u001b[0;34m(self, fn, *args)\u001b[0m\n\u001b[1;32m   1334\u001b[0m         \u001b[0;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1335\u001b[0m           \u001b[0;32mpass\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1336\u001b[0;31m       \u001b[0;32mraise\u001b[0m \u001b[0mtype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0me\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnode_def\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mop\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmessage\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1337\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1338\u001b[0m   \u001b[0;32mdef\u001b[0m \u001b[0m_extend_graph\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mFailedPreconditionError\u001b[0m: Attempting to use uninitialized value dense_4/kernel\n\t [[Node: dense_4/kernel/read = Identity[T=DT_FLOAT, _class=[\"loc:@dense_4/kernel\"], _device=\"/job:localhost/replica:0/task:0/device:CPU:0\"](dense_4/kernel)]]\n\nCaused by op u'dense_4/kernel/read', defined at:\n  File \"/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py\", line 174, in _run_module_as_main\n    \"__main__\", fname, loader, pkg_name)\n  File \"/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py\", line 72, in _run_code\n    exec code in run_globals\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/ipykernel_launcher.py\", line 16, in <module>\n    app.launch_new_instance()\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/traitlets/config/application.py\", line 658, in launch_instance\n    app.start()\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/ipykernel/kernelapp.py\", line 477, in start\n    ioloop.IOLoop.instance().start()\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/zmq/eventloop/ioloop.py\", line 177, in start\n    super(ZMQIOLoop, self).start()\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/tornado/ioloop.py\", line 888, in start\n    handler_func(fd_obj, events)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/tornado/stack_context.py\", line 277, in null_wrapper\n    return fn(*args, **kwargs)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/zmq/eventloop/zmqstream.py\", line 440, in _handle_events\n    self._handle_recv()\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/zmq/eventloop/zmqstream.py\", line 472, in _handle_recv\n    self._run_callback(callback, msg)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/zmq/eventloop/zmqstream.py\", line 414, in _run_callback\n    callback(*args, **kwargs)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/tornado/stack_context.py\", line 277, in null_wrapper\n    return fn(*args, **kwargs)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/ipykernel/kernelbase.py\", line 283, in dispatcher\n    return self.dispatch_shell(stream, msg)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/ipykernel/kernelbase.py\", line 235, in dispatch_shell\n    handler(stream, idents, msg)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/ipykernel/kernelbase.py\", line 399, in execute_request\n    user_expressions, allow_stdin)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/ipykernel/ipkernel.py\", line 196, in do_execute\n    res = shell.run_cell(code, store_history=store_history, silent=silent)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/ipykernel/zmqshell.py\", line 533, in run_cell\n    return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/IPython/core/interactiveshell.py\", line 2718, in run_cell\n    interactivity=interactivity, compiler=compiler, result=result)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/IPython/core/interactiveshell.py\", line 2822, in run_ast_nodes\n    if self.run_code(code, result):\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/IPython/core/interactiveshell.py\", line 2882, in run_code\n    exec(code_obj, self.user_global_ns, self.user_ns)\n  File \"<ipython-input-3-ed082c4f0622>\", line 26, in <module>\n    best_player = agent.Agent(state_size, action_size, MCTSsimulations)\n  File \"agent.py\", line 33, in __init__\n    self.model = self._build_model(model)\n  File \"agent.py\", line 44, in _build_model\n    model.add(Dense(10, use_bias=True, bias_initializer='random_uniform', activation='relu', kernel_regularizer=regularizers.l2(0.00001), input_dim=self.state_size))\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/keras/models.py\", line 442, in add\n    layer(x)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/keras/engine/topology.py\", line 575, in __call__\n    self.build(input_shapes[0])\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/keras/layers/core.py\", line 828, in build\n    constraint=self.kernel_constraint)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/keras/legacy/interfaces.py\", line 87, in wrapper\n    return func(*args, **kwargs)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/keras/engine/topology.py\", line 399, in add_weight\n    constraint=constraint)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py\", line 316, in variable\n    v = tf.Variable(value, dtype=_convert_string_dtype(dtype), name=name)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/tensorflow/python/ops/variables.py\", line 213, in __init__\n    constraint=constraint)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/tensorflow/python/ops/variables.py\", line 360, in _init_from_args\n    self._snapshot = array_ops.identity(self._variable, name=\"read\")\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/tensorflow/python/ops/array_ops.py\", line 125, in identity\n    return gen_array_ops.identity(input, name=name)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/tensorflow/python/ops/gen_array_ops.py\", line 2108, in identity\n    \"Identity\", input=input, name=name)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py\", line 787, in _apply_op_helper\n    op_def=op_def)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/tensorflow/python/framework/ops.py\", line 2991, in create_op\n    op_def=op_def)\n  File \"/Users/davidfoster/.virtualenvs/deepreinforcement/lib/python2.7/site-packages/tensorflow/python/framework/ops.py\", line 1479, in __init__\n    self._traceback = self._graph._extract_stack()  # pylint: disable=protected-access\n\nFailedPreconditionError (see above for traceback): Attempting to use uninitialized value dense_4/kernel\n\t [[Node: dense_4/kernel/read = Identity[T=DT_FLOAT, _class=[\"loc:@dense_4/kernel\"], _device=\"/job:localhost/replica:0/task:0/device:CPU:0\"](dense_4/kernel)]]\n"
     ]
    }
   ],
   "source": [
    "###### QUESTION 1 #########\n",
    "for i in range(best_player_version+1):\n",
    "    preds = best_players[i].predict(np.array([[1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0]], dtype=np.int))\n",
    "    print(round(preds[0],2))\n",
    "    print([round(np.exp(x) / (1 + np.exp(x)),2) for x in preds[1:]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'Sequential' object has no attribute 'size'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-13-c60f811ca67e>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mbest_players\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msize\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m: 'Sequential' object has no attribute 'size'"
     ]
    }
   ],
   "source": [
    "best_players[i].model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[[array([0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0]),\n",
       "  array([ 0.82608696,  0.        ,  0.        ,  0.06521739,  0.        ,\n",
       "          0.02173913,  0.        ,  0.06521739,  0.02173913]),\n",
       "  1,\n",
       "  1],\n",
       " [array([1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1]),\n",
       "  array([ 0.        ,  0.18181818,  0.        ,  0.16666667,  0.        ,\n",
       "          0.        ,  0.46969697,  0.18181818,  0.        ]),\n",
       "  -1,\n",
       "  -1]]"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import itertools\n",
    "output = list(itertools.islice(env.memory, 71, 73))\n",
    "output"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import tensorflow as tf\n",
    "from loss import cemse\n",
    "from keras import losses\n",
    "\n",
    "data = list(itertools.islice(env.memory, 0, 73))\n",
    "# data = env.memory\n",
    "\n",
    "sess = tf.Session()\n",
    "\n",
    "preds = current_player.predict(np.array([e[0] for e in data]))\n",
    "\n",
    "y_true = tf.constant(np.array([np.append(m[3], m[1]) for m in data]), dtype='float64')\n",
    "y_pred = tf.constant(preds, dtype='float64')\n",
    "\n",
    "#print('Y_TRUE')\n",
    "#print(sess.run(y_true))\n",
    "#print('Y_PRED')\n",
    "#print(sess.run(y_pred))\n",
    "\n",
    "v = tf.slice(y_pred, [0,0], [-1,1])\n",
    "z = tf.slice(y_true, [0,0], [-1,1])\n",
    "\n",
    "#print('TANH VALUE')\n",
    "#print(sess.run(tf.tanh(v)))\n",
    "#print('ACTUAL WINNER')\n",
    "#print(sess.run(z))\n",
    "\n",
    "p = tf.slice(y_pred, [0,1], [-1,-1])\n",
    "pi = tf.slice(y_true, [0,1], [-1,-1])\n",
    "\n",
    "#print('EXP LOGIT')\n",
    "#print(sess.run(tf.exp(p)/ tf.reduce_sum(tf.exp(p), axis = 1, keep_dims = True)))\n",
    "#print('ACTUAL PI')\n",
    "#print(sess.run(pi))\n",
    "\n",
    "\n",
    "\n",
    "loss1 = losses.mean_squared_error(z, tf.tanh(v))\n",
    "loss2 = tf.nn.softmax_cross_entropy_with_logits(labels = pi, logits = p)\n",
    "\n",
    "loss = cemse(y_true, y_pred)\n",
    "\n",
    "\n",
    "total_loss = tf.reduce_mean(loss)\n",
    "total_loss1 = tf.reduce_mean(loss1)\n",
    "total_loss2 = tf.reduce_mean(loss2)\n",
    "\n",
    "print('LOSSES')\n",
    "#print(sess.run(loss))\n",
    "#print(sess.run(loss1))\n",
    "#print(sess.run(loss2))\n",
    "\n",
    "print(sess.run(total_loss))\n",
    "print(sess.run(total_loss1))\n",
    "print(sess.run(total_loss2))\n",
    "\n",
    "print('------')\n",
    "\n",
    "print(sess.run(tf.reduce_mean(tf.abs(z - tf.tanh(v)))))\n",
    "print(sess.run(tf.reduce_mean(tf.abs(pi - p))))\n",
    "\n",
    "#print(preds[2])\n",
    "#print(np.array([np.append(m[3], m[1]) for m in env.memory])[2])\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "deepreinforcement",
   "language": "python",
   "name": "deepreinforcement"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
